using System;
using System.Collections.Generic;
using System.Linq;

namespace UnitTests
{
	public static class Rand
	{
		private static readonly Random Random = new Random();


		/// <summary>
		/// Gets a random boolean
		/// </summary>
		public static bool Bool
		{
			get { return Random.Next(2) == 1; }
		}

		/// <summary>
		/// Gets a random string
		/// </summary>
		public static string String
		{
			get { return Guid.NewGuid().ToString().Replace("-", ""); }
		}

		/// <summary>
		/// Gets a random integer
		/// </summary>
		/// <param name="max">The max(exclusive)</param>
		/// <returns></returns>
		public static int Int(int max)
		{
			return Random.Next(max);
		}

		/// <summary>
		/// Gets a random integer
		/// </summary>
		/// <param name="min">The min(inclusive)</param>
		/// <param name="max">The max(exclusive)</param>
		/// <returns></returns>
		public static int Int(int min, int max)
		{
			return Random.Next(min, max);
		}

		/// <summary>
		/// Returns a random object in the objects
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="objects">The target objects.</param>
		/// <returns></returns>
		public static T Object<T>(IEnumerable<T> objects)
		{
			T[] array = objects.ToArray();
			return array[Int(array.Length)];
		}

		/// <summary>
		/// Returns a random object expcept the excepted object.
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="objects">The target objects.</param>
		/// <param name="exceptedObject">The excepted object.</param>
		/// <returns></returns>
		public static T Object<T>(IEnumerable<T> objects, T exceptedObject)
		{
			T obj = default(T);
			do
			{
				obj = Object(objects);
			} while (Equals(obj, exceptedObject));
			return obj;
		}

		/// <summary>
		/// Returns a random object expcept satisfing the excepted condition.
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="objects">The target objects.</param>
		/// <param name="exceptedCondition">The excepted condition.</param>
		/// <returns></returns>
		public static T Object<T>(IEnumerable<T> objects, Func<T, bool> exceptedCondition)
		{
			T obj = default(T);
			do
			{
				obj = Object(objects);
			} while (exceptedCondition(obj));
			return obj;
		}

		public static string[] Strings(int count)
		{
			var strings = new string[count];
			for (int i = 0; i < strings.Length; i++)
			{
				strings[i] = String;
			}
			return strings;
		}
	}
}